var reviveCount = -100;
var mapIds = [800021000];
var 准备地图 = 800021100;
var eventName = "蘑菇神社_恶鬼之森";

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance(eventName);
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully()
    }
    return c
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(1000 * 60 * 3);
    b.schedule("怪物1", 30 * 1000);
    b.schedule("怪物2", 60 * 1000);
    b.schedule("怪物3", 90 * 1000)
}

function 怪物1(a) {
    a.getPlayers().forEach(function (b) {
        b.getAPI().addPopupSay(9111062, 2000, "当心右边！", "", 0);
        b.getAPI().spawnMobLimit(9400032, 1, 3250, -91, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3260, -98, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3270, -105, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3280, -111, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3285, -115, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3290, -118, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3300, -125, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3305, -128, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3310, -131, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3315, -135, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3325, -141, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3330, -145, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3335, -145, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3340, -145, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3345, -145, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3106, -25, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3036, -9, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3151, -25, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3088, -25, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3036, -9, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3097, -25, 100)
    })
}

function 怪物2(a) {
    a.getPlayers().forEach(function (b) {
        b.getAPI().spawnMobLimit(9400032, 1, 3122, -25, 100);
        b.getAPI().addPopupSay(9111062, 2000, "看好了，这次妖鬼是从中间攻过来。快把他们统统消灭！", "", 0);
        b.getAPI().spawnMobLimit(9400033, 1, 2600, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2620, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2630, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2660, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2680, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2720, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2740, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2770, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2780, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2800, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2820, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2840, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2850, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2860, 35, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2870, 35, 100)
    })
}

function 怪物3(a) {
    a.getPlayers().forEach(function (b) {
        b.getAPI().spawnMobLimit(9400032, 1, 3098, -25, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3699, -145, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3445, -145, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3212, -66, 100);
        b.getAPI().spawnMobLimit(9400032, 1, 3480, -145, 100);
        b.getAPI().spawnMobLimit(9400033, 1, 2536, 35, 100);
        b.getAPI().addPopupSay(9111062, 2000, "哦！是变种妖鬼！看起来更厉害啊！当心！", "", 0);
        b.getAPI().spawnMobLimit(9400053, 1, 2700, 35, 100)
    })
}

function onPlayerRevived(b, a) {
    return false
}

function onMonsterKilled(b, d) {
    var c = em.getNumberProperty("state");
    var e = 16;
    var a = em.getNumberProperty("stage" + c + "_kill") + 1;
    em.setProperty("stage" + c + "_kill", a);
    if (a == 59) {
        player.getAPI().fieldEffect_ScreenMsg("monsterPark/clearF");
        player.getAPI().updateInfoQuest(58730, "state=3");
        player.getAPI().setPartner(0, 9111011, 0, 0);
        player.scheduleWarpTask(3, 800021102, 0, false)
    }
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    switch (a) {
        case 302050100:
            initProp("stage" + 1 + "_kill", 0);
            break;
        case 302050200:
            initProp("stage" + 1 + "_kill", 0);
            break;
        case 302050300:
            initProp("stage" + 1 + "_kill", 0);
            break
    }
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
};